home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbser320.zip / OFFHOOK.BAS < prev    next >
BASIC Source File  |  1992-10-20  |  4KB  |  135 lines

  1.     DEFINT A-Z
  2.  
  3.     DECLARE SUB Response ()
  4.     DECLARE FUNCTION Value% (Char$)
  5.  
  6. '   This example program is used to take the modem OFF-HOOK and leave it that
  7. '   way. This program was designed to work with a PCBoard BBS system and
  8. '   the port (and perhaps IRQ) information is retrieved from a system file
  9. '   called PCBOARD.DAT. In order to experiment with this program in a
  10. '   non-PCBoard environment, simply remove the lines marked "NO PCBOARD START"
  11. '   until "NO PCBOARD END". Then Add the following variables before the
  12. '   OpenComm statement:
  13. '
  14. '   Port        The port number (1, 2, 3, 4, or any other address)
  15. '   Rate&       The baud rate you want to use (2400, 9600, etc)
  16. '   OffHook$    A string with your modem's off hook command (ATH1)
  17.  
  18. '   $INCLUDE: 'QBSERIAL.DEC'
  19.  
  20.     CLS
  21.     IRQ = 0
  22.     PRINT "Modem OFFHOOK, ver 1.0"
  23.     PRINT
  24.  
  25. ' Print Driver Copyright
  26.  
  27.     X& = DriverCopyright
  28.     WHILE (PEEK(X&))
  29.         CP$ = CP$ + CHR$(PEEK(X&))
  30.         X& = X& + 1
  31.     WEND
  32.     PRINT CP$
  33.     PRINT
  34.  
  35. '----------NO PCBOARD START--------------------------------------------------
  36.     OPEN "PCBOARD.DAT" FOR INPUT AS #1
  37.  
  38.     FOR Lp = 1 TO 52
  39.         INPUT #1, Port$
  40.     NEXT
  41.     INPUT #1, Speed$            'Get Port Speed from PCBOARD.DAT
  42.     INPUT #1, X$
  43.     INPUT #1, X$
  44.     INPUT #1, OffHook$          'Get OFF-HOOK string from PCBOARD.DAT
  45.     Rate& = VAL(Speed$)
  46.     IF Port$ = "NONE" THEN
  47.         PRINT "No Modem."
  48.         END
  49.     END IF
  50.     Port = VAL(MID$(Port$, 4))      'Get port used
  51.     IF Port > 2 THEN                'If port isnt 1 or 2, then you need IRQ
  52.         SEEK #1, 1                  'and Base Address
  53.         FOR Lp = 1 TO 159
  54.             INPUT #1, IRQ$          'get IRQ
  55.         NEXT
  56.         INPUT #1, Port$             'get BASE ADDRESS of port
  57.  
  58.         ' Convert (ascii) HEX value of port to useable decimal value
  59.  
  60.         Port = (Value(MID$(Port$, 1, 1)) * 256) + (Value(MID$(Port$, 2, 1)) * 16) + Value(MID$(Port$, 3, 1))
  61.         IRQ = VAL(IRQ$)
  62.     END IF
  63. '----------NO PCBOARD END----------------------------------------------------
  64.  
  65.     CRLF$ = CHR$(13) + CHR$(10)
  66.     Length = 8
  67.     Parity = 0
  68.     HS = 0
  69.  
  70.     OpenComm Port, IRQ, Length, Parity, Rate&, HS, 0
  71.  
  72.     CarrierDetect 0     ' <-- NEEDED TO TALK TO MODEM W/NO CARRIER!!
  73.  
  74.     ClearInputBuffer
  75.     transmit "AT" + CRLF$
  76.     PRINT "Transmitting: AT"
  77.     Response
  78.     PRINT
  79.  
  80.     SLEEP 1
  81.  
  82.     ClearInputBuffer
  83.     transmit "AT" + CRLF$
  84.     PRINT
  85.     PRINT "Transmitting: AT"
  86.     Response
  87.     PRINT
  88.  
  89.     SLEEP 1
  90.  
  91.     ClearInputBuffer
  92.     transmit OffHook$ + CRLF$
  93.     PRINT
  94.     PRINT "Transmitting: " + OffHook$
  95.     Response
  96.     PRINT
  97.  
  98.     SLEEP 2
  99.  
  100.     DTRcontrol 1            ' DONT turn off DTR, doing so may let modem
  101.                             ' hang up, and we dont want this to happen
  102.     CloseComm
  103.  
  104.     END
  105.  
  106. ' Read data comming from the modem. SUB will not return until an OK is
  107. ' detected. SUB will time-out if an OK is not detected in 4 seconds.                                                    
  108. SUB Response
  109.     Start! = TIMER
  110.     PRINT "Response: ";
  111.     I$ = ""
  112.     DO
  113.         IF DataWaiting THEN
  114.             X$ = CHR$(ReadChar)
  115.             PRINT X$;
  116.             I$ = I$ + X$
  117.         END IF
  118.         IF TIMER - Start! > 4 THEN
  119.             PRINT "COMMUNICATIONS TIMEOUT!!"
  120.             EXIT DO
  121.         END IF
  122.     LOOP UNTIL INSTR(I$, "OK")
  123. END SUB
  124.  
  125. FUNCTION Value (Char$)
  126.     SELECT CASE Char$
  127.         CASE "0" TO "9"
  128.             Value = VAL(Char$)
  129.             EXIT FUNCTION
  130.         CASE "A" TO "F"
  131.             Value = ASC(Char$) - 55
  132.     END SELECT
  133. END FUNCTION
  134.  
  135.